package com.example.recyleranima;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;

import com.example.recyleranima.expandablelayout.main.ExpandActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;

public class MainActivity extends AppCompatActivity {
    private Button btnH;
    private Button btnV;
    private RecyclerView recyclerViewH;
    private RecyclerView recyclerViewV;
    private List<String> contacts = new ArrayList<>();


    private MainAdapter mAdapter;
    private Button btnStart;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initData();
        ButterKnife.bind(this);
        btnH = findViewById(R.id.btn_h);
        btnV = findViewById(R.id.btn_v);

        btnStart = findViewById(R.id.btn_start);
        recyclerViewH = findViewById(R.id.rv_h);
        recyclerViewV = findViewById(R.id.rv_v);
        /***横向***/
        recyclerViewH.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
        recyclerViewH.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.HORIZONTAL));
        mAdapter = new MainAdapter(this, contacts);
        recyclerViewH.setAdapter(mAdapter);

        DefaultItemAnimator defaultItemAnimator = new DefaultItemAnimator();
        defaultItemAnimator.setAddDuration(1000);
        defaultItemAnimator.setRemoveDuration(1000);
        recyclerViewH.setItemAnimator(defaultItemAnimator);

        /***竖向***/
        recyclerViewV.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
        recyclerViewV.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
        mAdapter = new MainAdapter(this, contacts);
        recyclerViewV.setAdapter(mAdapter);
        /**
         * 既然是动画，就会有时间，我们把动画执行时间变大一点来看一看效果
         */
        DefaultItemAnimator itemAnimator = new DefaultItemAnimator();
        itemAnimator.setAddDuration(1000);
        itemAnimator.setRemoveDuration(1000);
        recyclerViewV.setItemAnimator(itemAnimator);


        btnH.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                mAdapter.addData(1);
                mAdapter.move(0, contacts.size() - 1);

            }
        });
        btnV.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                mAdapter.removeData(1);

            }
        });

        btnStart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(MainActivity.this, ExpandActivity.class));
            }
        });

    }


    private void initData() {
        contacts.add("Amanda M1");
        contacts.add("Anquises2");
        contacts.add("Bellisima3");
        contacts.add("Bodo4");
        contacts.add("Brogan5");
        contacts.add("Brogan6");
        contacts.add("Brogan7");
        contacts.add("Brogan8");
        contacts.add("Brogan9");
    }


}
